<?
//fopen("search.html",'a');
echo "<a href=\"search.php\">Enter The Search Web.</a>";
//fopen("search_result.php",'w');
//get_magic_quotes_gpc魔术引擎是否开启
//建立了一个图书搜索页面，下面再创建一个图书插入页面。假如已经获得了登录权限。
//fopen("releasebook.php","a");
//fopen("insert_book.php","a");

/*11.4绑定参数插入数据 prepared方法*/  

require("database.inc");  
$con=new mysqli($lu_host,$lu_user,$lu_psw,$lu_db);  

//use prepared insert (bind_param)
$isbn='1-111-11111-7';  
$author='wenbo'; 
$title='how to kill you';  
$price=71;

$str2="insert into books values (?,?,?,?)"; //use ? to replace the param 
$result_check=$con->query("select * from books where isbn='".$isbn."'"); 
if($result_check->num_rows != 0){echo "The Book is exist.<br />";} //check if the record is exist.
else{
$result2=$con->prepare($str2);  
$result2->bind_param("sssd",$isbn,$author,$title,$price);  
$result2->execute(); 
echo $result2->affected_rows.'book inserted into database';  
}

//use prepared to select(bind_result)
//1.select string
$selectstr="select isbn,title,author,price from books";
//2.prepare select
$result3=$con->prepare($selectstr);
//3.bind result
$result3->bind_result($isbn2,$title2,$author2,$price2);
//4.excute the select
$result3->execute();
//5.echo the result use while
while($result3->fetch()){
	echo "ISBN:$isbn2 <br />";
	echo "Title:$title2 <br />";
	echo "Author:$author2 <br />";
	echo "Price:$price2 <br /><br />";
	}
//it has a problem Price:30.239999771118 should be 30.24,dont know why
//i should use decimal.http://blog.csdn.net/howroad/article/details/78202832

/*11.5使用php与数据库交互的其他借口*/ 
//下载pear  http://pear.php.net/go-pear.phar

//require_once("Mail.php");
//因为pear 安装一直失败，所以暂时不研究这一篇了……





?>